Skip to main content

DefaultFirstClickRepo

Stores information about the first clicks on the 'Magnet' and 'Brush' buttons, as well as whether a text drawing (Text or Callout) was set for the first time.

Default implementation of the repository:

/**
* Default implementation of [DrawingsFirstClickRepo].
*
* This class provides a default implementation of the [DrawingsFirstClickRepo] interface,
* managing the first click actions in the drawing toolbar with no persistence across application restarts.
*
* @property isMagnetModeClicked Indicates whether the "Magnet" button on the drawing toolbar has been clicked. Default is false.
* @property isDrawingModeClicked Indicates whether the "Brush" button on the drawing toolbar has been clicked. Default is false.
* @property isDrawingTextShowed Indicates whether a text drawing has been shown. Default is false.
* @property setMagnetModeClicked Callback function to set the "Magnet" button clicked status.
* @property setDrawingModeClicked Callback function to set the "Brush" button clicked status.
* @property setDrawingTextShowed Callback function to set the text drawing status.
* @constructor Creates a DefaultFirstClickRepo with the specified callbacks.
*/
open class DefaultFirstClickRepo(
private val isMagnetModeClicked: () -> Boolean,
private val isDrawingModeClicked: () -> Boolean,
private val isDrawingTextShowed: () -> Boolean,
private val setMagnetModeClicked: (Boolean) -> Unit,
private val setDrawingModeClicked: (Boolean) -> Unit,
private val setDrawingTextShowed: (Boolean) -> Unit,
) : DrawingsFirstClickRepo {
/**
* Method called when the "Magnet" button on the drawing toolbar is clicked.
* Returns true if called for the first time, otherwise returns false.
*
* @return True if the "Magnet" button is clicked for the first time, false otherwise.
*/
override fun magnetModeClicked(): Boolean {
return if (!isMagnetModeClicked()) {
setMagnetModeClicked(true)
true
} else {
false
}
}
/**
* Method called when the "Brush" button on the drawing toolbar for drawing is clicked.
* Returns true if called for the first time, otherwise returns false.
*
* @return True if the "Brush" button is clicked for the first time, false otherwise.
*/
override fun drawingModeClicked(): Boolean {
return if (!isDrawingModeClicked()) {
setDrawingModeClicked(true)
true
} else {
false
}
}
/**
* Method called when a text drawing is set.
* Returns true if called for the first time, otherwise returns false.
*
* @return True if a text drawing is shown for the first time, false otherwise.
*/
override fun drawingTextShowed(): Boolean {
return if (!isDrawingTextShowed()) {
setDrawingTextShowed(true)
true
} else {
false
}
}
}

Implementation of the default repository for local storage:

/**
* Local storage-based implementation of [DrawingsFirstClickRepo].
*
* This class provides a local storage-based implementation of the [DrawingsFirstClickRepo] interface,
* managing the first click actions in the drawing toolbar with no persistence across application restarts.
*
* @constructor Creates a LocalStorageDefaultFirstClickRepo.
*/
class LocalStorageDefaultFirstClickRepo : DrawingsFirstClickRepo {
/**
* Indicates whether the "Magnet" button on the drawing toolbar has been clicked.
*/
private var magnetModeClicked = false
/**
* Indicates whether the "Brush" button on the drawing toolbar has been clicked.
*/
private var drawingModeClicked = false
/**
* Indicates whether a text drawing has been shown.
*/
private var drawingTextClicked = false
/**
* The default repository instance using local storage.
*/
private val defaultRepo = DefaultFirstClickRepo(
isMagnetModeClicked = { magnetModeClicked },
isDrawingModeClicked = { drawingModeClicked },
isDrawingTextShowed = { drawingTextClicked },
setMagnetModeClicked = { magnetModeClicked = it },
setDrawingModeClicked = { drawingModeClicked = it },
setDrawingTextShowed = { drawingTextClicked = it }
)
/**
* Method called when the "Magnet" button on the drawing toolbar is clicked.
* Returns true if called for the first time, otherwise returns false.
*
* @return True if the "Magnet" button is clicked for the first time, false otherwise.
*/
override fun magnetModeClicked(): Boolean {
return defaultRepo.magnetModeClicked()
}
/**
* Method called when the "Brush" button on the drawing toolbar for drawing is clicked.
* Returns true if called for the first time, otherwise returns false.
*
* @return True if the "Brush" button is clicked for the first time, false otherwise.
*/
override fun drawingModeClicked(): Boolean {
return defaultRepo.drawingModeClicked()
}
/**
* Method called when a text drawing is set.
* Returns true if called for the first time, otherwise returns false.
*
* @return True if a text drawing is shown for the first time, false otherwise.
*/
override fun drawingTextShowed(): Boolean {
return defaultRepo.drawingTextShowed()
}
}